/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eddie;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 *
 * @author Eddie
 */
public class AddGame extends javax.swing.JFrame {

    /**
     * Creates new form AddGame
     */
    public AddGame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nameLabel = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        genreLabel = new javax.swing.JLabel();
        locationTextField = new javax.swing.JTextField();
        locationLabel = new javax.swing.JLabel();
        genreTextField = new javax.swing.JTextField();
        findGameButton = new javax.swing.JButton();
        addGameButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Add Game");
        setName("addGaneFrame"); // NOI18N

        nameLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        nameLabel.setText("Name");

        genreLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        genreLabel.setText("Genre");

        locationLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        locationLabel.setText("Location");

        findGameButton.setText("Find Game");
        findGameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findGameButtonActionPerformed(evt);
            }
        });

        addGameButton.setText("Add Game");
        addGameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addGameButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(nameLabel)
                            .addComponent(genreLabel))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nameTextField)
                            .addComponent(genreTextField)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(locationLabel)
                        .addGap(14, 14, 14)
                        .addComponent(locationTextField))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(findGameButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
                        .addComponent(addGameButton)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {addGameButton, findGameButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameLabel)
                    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(genreLabel)
                    .addComponent(genreTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(locationLabel)
                    .addComponent(locationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(findGameButton)
                    .addComponent(addGameButton))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void findGameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findGameButtonActionPerformed
        findGame();
    }//GEN-LAST:event_findGameButtonActionPerformed

    private void addGameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGameButtonActionPerformed
        addGame();
    }//GEN-LAST:event_addGameButtonActionPerformed
    String userhome = System.getProperty("user.home");
    JFileChooser fileChooser = new JFileChooser(userhome + "\\Desktop");
    FileNameExtensionFilter filterShortcuts = new FileNameExtensionFilter("Shortcuts", "lnk");
    FileNameExtensionFilter filterSteam = new FileNameExtensionFilter("Steam Games Shortcuts", "url");
    FileNameExtensionFilter filterExe = new FileNameExtensionFilter("Games", "exe");
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addGameButton;
    private javax.swing.JButton findGameButton;
    private javax.swing.JLabel genreLabel;
    private javax.swing.JTextField genreTextField;
    private javax.swing.JLabel locationLabel;
    private javax.swing.JTextField locationTextField;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    // End of variables declaration//GEN-END:variables

    private void addGame() {
        Game game = new Game(nameTextField.getText(), genreTextField.getText(), locationTextField.getText());
        this.dispose();

    }

    private void findGame() {
        fileChooser.setAcceptAllFileFilterUsed(false);
        fileChooser.addChoosableFileFilter(filterShortcuts);
        fileChooser.addChoosableFileFilter(filterExe);
        fileChooser.addChoosableFileFilter(filterSteam);
        fileChooser.showOpenDialog(this);
        try {
            nameTextField.setText(fileChooser.getSelectedFile().getName());
            locationTextField.setText(fileChooser.getSelectedFile().getPath());
        } catch (NullPointerException e) {
        }
    }
}
